package com.xinhe.web.reposity;

import com.xinhe.web.entity.Attach;
import com.xinhe.web.response.AttachView;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Set;

public interface AttachRepository extends JpaRepository<Attach, Long> {
    @Query(value = "select * from tb_attach where removed =0 and f_business_id in ?1", nativeQuery = true)
    List<AttachView> pageAttach(Set<Long> businessId);
    @Query(value = "select * from tb_attach where removed =0 and f_business_id in ?1 and type=?2", nativeQuery = true)
    List<AttachView> pageAttach(Set<Long> businessId,String type);
    @Query(value = "select * from tb_attach where removed =0 and f_business_id = ?1", nativeQuery = true)
    List<Attach> findByBusinessId(Long businessId);

    @Modifying
    @Query(value = "update tb_attach set removed = 0,f_business_id = ?1 where id in ?2 ", nativeQuery = true)
    void updateAttachByBusinessIdAndAttachIds(Long businessId, Set<Long> attachIds);

}
